<?php
class Userimages_Model_Pagedecision implements Userimages_Model_Mainable{
    
    private $core_controller_csrftoken;
    private $action_handler;
    private $get_current_imagedata;
    
    public function main(array $variables = null) {
        switch($variables['get']['page']){
            case 'dodaj-zdjecie':
                return $this->add_image($variables);
                break;
            case 'wstaw-zdjecie':
                return $this->insert_image($variables);
                break;
            case 'edytuj-zdjecie':
                return $this->edit_image($variables);
                break;
            case 'aktualizuj-zdjecie':
                return $this->update_image($variables);
                break;
            default :
                return $this->default_action($variables);
                break;
        }
    }
    
    private function update_image(array $variables = null){
        $this->action_handler = new Userimages_Model_Updateimage;
        return $this->action_handler->main($variables);
    }
    
    private function edit_image(array $variables = null){
        $page = $this->get_other_data($variables);
        $this->get_current_imagedata = new Userimages_Data_Getcurrentimage;
        $page['content'] = $this->get_current_imagedata->main($variables);
        return $page;
    }
    
    private function insert_image(array $variables = null){
        $this->action_handler = new Userimages_Model_Insertimage;
        return $this->action_handler->main($variables);
    }
    
    private function add_image(array $variables = null){
        $page = $this->get_other_data($variables);
        return $page;
    }
    
    private function get_other_data(array $variables = null){
        $this->core_controller_csrftoken = new Core_Controller_Csrftoken;
        $page['csrf_token'] = $this->core_controller_csrftoken->main($variables);
        $page['template'] = WEB_ROOT_FOLDER."userimages/views/addimage.php";
        return $page;
    }
    
    private function default_action(array $variables = null){
        unset($variables['get']);
        $this->action_handler = new Userimages_Model_Userimages;
        return $this->action_handler->main($variables);
    }

}
